<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>合并和展平</title>
</head>
<body>

  <script>
    let arr1 = ['a', 'b'];
    let arr2 = ['c', 'd'];

    let arr3 = arr1.concat(arr2);
    console.log(arr3)

    let arr4 = [...arr1, ...arr2];
    console.log(arr4)


    // 数组展平 9
    let arr =  [1, 2, [3, 4], [5, 6, [7, 8, 9]]];

    //1. 直接用 flat API
    let arr5 = arr.flat(Infinity)
    console.log(arr5)
    

    // 2. 先转换成字符串join再转换成数组split,但是这时数组里面都是字符形式， map生成数值
    let arr6 = arr.join().split(',').map(Number)
    console.log(arr6)

    console.log(arr.join())
    console.log(arr.join().split(','))


  </script>
</body>
</html>